home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 7740 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  72 lines

  1. Path: news.eunet.ch!usenet
  2. From: Oliver Plohmann <opl@esec.ch>
  3. Newsgroups: comp.lang.c++
  4. Subject: Binary association problem
  5. Date: Mon, 19 Feb 1996 10:21:17 +0100
  6. Organization: ESEC SA
  7. Message-ID: <3128410D.6E80@esec.ch>
  8. NNTP-Posting-Host: everest.esec.ch
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0b6a (X11; I; HP-UX A.09.05 9000/735)
  13. CC: Oliver Plohmann <opl@al.esec.ch>
  14.  
  15. Hello,
  16.  
  17. I habe two classes that reference each other. I put those classes into
  18. one header to get the code linked. Due to the nature of my application I
  19. have now several class associated with each eather in one header. My
  20. compiler can't handle it any more and creates a fatal error. I could
  21. switch compiler but every compiler has some problem. I think it would
  22. only mean substituting problems for other problems.
  23.  
  24. To split up the code into separate headers I have changed associations
  25. between classes to be pointer references (otherwise I get cyclic
  26. inclusion of headers). Whith this approach the code compiles and links
  27. fine. Below some sample code to show this. Unhappily, I get a protection
  28. violation. The reason is probably a scoping issue. Does anybody know a
  29. way out of this?
  30.  
  31. Thank you, Olli Plohmann
  32.  
  33. -------------------------a.h------------------------
  34.  
  35. class B;
  36.  
  37. class A {
  38.  
  39.     int* x;
  40. public:
  41.  
  42.     A() {};
  43.     ~A() {};
  44.  
  45.     void operator+(const int& i) { 
  46.         *x=i;    // protection violation ! 
  47.     };
  48. };
  49.  
  50. -------------------------b.h------------------------
  51. #include "a.h"
  52.  
  53. class A;
  54.  
  55. class B {
  56.  
  57.     A* x;
  58. public:
  59.  
  60.     B() { *x=5; };
  61.     ~B() {};
  62. }; 
  63.  
  64. --------------------------test.cpp--------------------
  65.  
  66. #include "b.h"
  67.  
  68. void main()
  69. {
  70.     B b;    // protection violation in A::operator=(const int& i)
  71. }
  72.